﻿using LibraryManagement.Custom_Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Transactions;
using System.Windows.Forms;

namespace LibraryManagement
{
    public partial class Testing : libForm
    {
        public Testing()
        {
            InitializeComponent();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                var encryption = clsEncyrption.CryptoMz.Encrypt(txtLibCode.Text, "tristana#18");
                lblPass.Text = encryption.ToString();
            }
            catch (Exception ex)
            {

            }
        }

        private void txtLibCode_TextChanged(object sender, EventArgs e)
        {
        }

        private void btnDecrypt_Click(object sender, EventArgs e)
        {
            try
            {
                //var decrypt = clsEncyrption.AES.Decrypt(lblPass.Text, "tristana#18");
                //lblPass2.Text = decrypt;
            }
            catch (Exception ex)
            {
            }
        }

        private void libButton1_Click(object sender, EventArgs e)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                var context = new LibManagementEntities();
                foreach (MemberDetail member in context.MemberDetails.ToList())
                {
                    var list = context.MemberDetails.Select(x => x.PinCode).ToList();
                    Random rnd = new Random();
                    while (true)
                    {
                        var pin = rnd.Next(1000, 9999);
                        if (!context.MemberDetails.Select(x => x.PinCode).ToList().Contains(pin.ToString().GetHashCode().ToString()))
                        {
                            member.PinCode = pin.ToString().GetHashCode().ToString();
                            break;
                        }
                        else
                        { }
                    }
                    context.SaveChanges();
                }

                ts.Complete();
            }
        }

        private void gridControl1_Click(object sender, EventArgs e)
        {

        }
    }
}
